package br.com.comanda.webservice.resources;

import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import br.com.comanda.webservice.business.AccountBusiness;
import br.com.comanda.webservice.model.Account;

@Path("/accounts")
public class AccountResources {

	private final AccountBusiness accountBusiness = new AccountBusiness();

	@GET
	@Produces({ MediaType.APPLICATION_JSON })
	public List<Account> getAccounts() {
		return this.accountBusiness.findAll();
	}

	@POST
	@Consumes({ MediaType.APPLICATION_JSON })
	@Produces({ MediaType.TEXT_HTML })
	public String addAccount(Account account) {
		this.accountBusiness.save(account);
		return "ok";
	}

	@Path("{id}")
	@PUT
	@Consumes({ MediaType.TEXT_PLAIN })
	@Produces({ MediaType.TEXT_HTML })
	public String closeAccount(@PathParam("id") int id) {
		this.accountBusiness.closeAccount(id);
		return "ok";
	}

}
